package com.quiz;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class SplashActivity extends Activity {

	private static final String TAG = "MediaPlayer";
	private MediaPlayer mediaPlayer;// playing sound
	private Animation animDropDown;// drop down
	private Animation animFadeIn;// fade in
	private ImageView imgQuiz;// drop down
	private ImageView imgShadow; // fade in

	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash_screen);
        
        //retrieve and play sound 
        try {
        	 mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.intro);
             mediaPlayer.start();
		} catch (Exception e) {
			// TODO: handle exception
			Log.e(TAG,"error: " + e.getMessage(), e);
		}
       
       
        // retrieve QUIZ image
        imgQuiz = (ImageView) findViewById(R.id.splash_quiz_icon);
        imgShadow = (ImageView) findViewById(R.id.splash_shadow);
        
        // setting animation
        animDropDown = AnimationUtils.loadAnimation(getBaseContext(), R.anim.drop_down);
        animDropDown.setStartOffset(0);
        animDropDown.setDuration(2000);
        imgQuiz.startAnimation(animDropDown);
        
        animFadeIn = AnimationUtils.loadAnimation(getBaseContext(), android.R.anim.fade_in);
        animFadeIn.setStartOffset(2500);
        animFadeIn.setDuration(1000);
        imgShadow.startAnimation(animFadeIn);
        
        // set onAnimationEnd to start MainActivity
        animFadeIn.setAnimationListener(new AnimationListener() {
			
			@Override
			public void onAnimationStart(Animation animation) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onAnimationRepeat(Animation animation) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onAnimationEnd(Animation animation) {
				// TODO Auto-generated method stub
				if(mediaPlayer != null) {
					mediaPlayer.release();
					mediaPlayer = null;
				}
				startActivity(new Intent(SplashActivity.this, HomeTabActivity.class));
				SplashActivity.this.finish();
			}
		});

    }
}